package com.ruoyi.web.controller.qingxun;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qingxun.domain.QxDrill;
import com.ruoyi.qingxun.service.IQxDrillService;

/**
 * 训练项目Controller
 * 
 * @author ruoyi
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/qingxun/drill")
public class QxDrillController extends BaseController
{
    @Autowired
    private IQxDrillService qxDrillService;
    
    /**
     * test
     */
//    @PreAuthorize("@ss.hasPermi('qingxun:drill:list')")
    @GetMapping("/test")
    public String test()
    {
        return "hello";
    }

    /**
     * 查询训练项目列表
     */
    @PreAuthorize("@ss.hasPermi('qingxun:drill:list')")
    @GetMapping("/list")
    public TableDataInfo list(QxDrill qxDrill)
    {
        startPage();
        List<QxDrill> list = qxDrillService.selectQxDrillList(qxDrill);
        return getDataTable(list);
    }

    /**
     * 导出训练项目列表
     */
    @PreAuthorize("@ss.hasPermi('qingxun:drill:export')")
    @Log(title = "训练项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QxDrill qxDrill)
    {
        List<QxDrill> list = qxDrillService.selectQxDrillList(qxDrill);
        ExcelUtil<QxDrill> util = new ExcelUtil<QxDrill>(QxDrill.class);
        util.exportExcel(response, list, "训练项目数据");
    }

    /**
     * 获取训练项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('qingxun:drill:query')")
    @GetMapping(value = "/{drillId}")
    public AjaxResult getInfo(@PathVariable("drillId") Long drillId)
    {
        return success(qxDrillService.selectQxDrillByDrillId(drillId));
    }

    /**
     * 新增训练项目
     */
    @PreAuthorize("@ss.hasPermi('qingxun:drill:add')")
    @Log(title = "训练项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QxDrill qxDrill)
    {
        return toAjax(qxDrillService.insertQxDrill(qxDrill));
    }

    /**
     * 修改训练项目
     */
    @PreAuthorize("@ss.hasPermi('qingxun:drill:edit')")
    @Log(title = "训练项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QxDrill qxDrill)
    {
        return toAjax(qxDrillService.updateQxDrill(qxDrill));
    }

    /**
     * 删除训练项目
     */
    @PreAuthorize("@ss.hasPermi('qingxun:drill:remove')")
    @Log(title = "训练项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drillIds}")
    public AjaxResult remove(@PathVariable Long[] drillIds)
    {
        return toAjax(qxDrillService.deleteQxDrillByDrillIds(drillIds));
    }
}
